var vm = new Vue({
    el:'#app',
    data: {
        stationData: {
            pointId:'',
            devCode:'',
        },
        options: [],
    },
    created: function () {
        let that = this;
        that.getPointIdAndDevCode();
        that.getCodeOptions();
    },
    mounted: function () {
        parent.modifyTitle('模型')
    },
    methods:{
        pointIdChange: function () {
            for(let i in this.options){
                if(this.stationData.pointId==this.options[i].value){
                    this.stationData.devCode = this.options[i].code;
                }
            }
        },
        toModel:function () {
            window.history.back(-1);
        },
        editModel: function (){
            var id = document.getElementById("modelId").value;
            var pointId = this.stationData.pointId;
            var deviceCode = this.stationData.devCode;
            var modelName = document.getElementById("modelName").value;
            var modelVersion = document.getElementById("modelVersion").value;
            console.log("id:",id,"pointId:",pointId,"deviceCode：",deviceCode,"modelName:",modelName,"modelVersion:",modelVersion);

            window.parent.layerAlert("你确定要修改该模型吗？", {
                icon: 3,
                title: "提示",
                btn:["确定","取消"],
                yes:function (){
                    $.ajax({
                        type: "GET",
                        url: "/multipower/model/update",
                        data: {
                            id: id,
                            deviceCode:deviceCode,
                            modelName:modelName,
                            modelVersion:modelVersion,
                            pointId: pointId
                        },
                        success: function () {
                            window.location.href = "/multipower/model.html";
                            window.parent.layerAlert("修改成功", {
                                icon: 6,
                                title: "提示"
                            });
                        },
                        error:function () {
                            window.parent.layerAlert("修改失败", {
                                icon: 5,
                                title: "提示"
                            });
                        }
                    })
                }
            });
        },
        getPointIdAndDevCode:function () {
            let id = $("#pointId").val();
            this.stationData.pointId = id;
            let devCode = $("#deviceCode").val();
            this.stationData.devCode = devCode;
        },
        getCodeOptions:function () {
            let that = this;
            $.ajax({
                type:'GET',
                url:'/multipower/point/getAll',
                success:function (data) {
                    if(data.status==1){
                        let res = [];
                        for(let i=0;i<data.data.length;i++){
                            res.push({
                                value: data.data[i].id,
                                label: data.data[i].pointName,
                                code: data.data[i].devCode,
                            });
                        }
                        that.options = [...res];
                        console.log("options:",that.options);
                    }else{
                        layer.alert(data.msg, {
                            icon: 5,
                            title: "提示"
                        });
                    }
                },
                failure:function (data) {
                    layer.alert(data.msg, {
                        icon: 5,
                        title: "提示"
                    });
                }
            })
        },
    }
})